package org.jsola.hr.helper;

import org.jsola.common.ClassKit;
import org.jsola.common.DateKit;
import org.jsola.common.SafeKit;
import org.jsola.hr.dto.AttendanceStatusAddDTO;
import org.jsola.hr.dto.AttendanceStatusUpdateDTO;
import org.jsola.hr.entity.AttendanceStatusDO;
import org.jsola.hr.query.AttendanceStatusQuery;
import org.jsola.hr.service.IAttendanceStatusService;
import org.jsola.hr.vo.AttendanceStatusVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.Date;
import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * @author zhr
 */
@Component
public class AttendanceStatusTestHelper extends BaseTestHelper {
    
    @Autowired
    private IAttendanceStatusService attendanceStatusService;

    /**
     * 生成add测试数据
     * @return AttendanceStatusAddDTO
     */
    public AttendanceStatusAddDTO getAttendanceStatusAddDTO(){
        AttendanceStatusAddDTO attendanceStatusAddDTO = new AttendanceStatusAddDTO();
        attendanceStatusAddDTO.setRecordId(getRandomValue("varchar",32));
        attendanceStatusAddDTO.setEmpId(getRandomValue("varchar",32));
        attendanceStatusAddDTO.setNumber(getRandomValue("varchar",32));
        attendanceStatusAddDTO.setDate((Date)ClassKit.getObjectValue(getRandomValue("date",0),"java.util.Date"));
        attendanceStatusAddDTO.setStatus(SafeKit.getInteger(getRandomValue("tinyint",4)));
        attendanceStatusAddDTO.setMinutes(SafeKit.getInteger(getRandomValue("int",11)));
        attendanceStatusAddDTO.setDeduction(SafeKit.getInteger(getRandomValue("int",11)));
        attendanceStatusAddDTO.setRemark(getRandomValue("varchar",255));
        attendanceStatusAddDTO.setCompanyId(getRandomValue("varchar",32));
        return attendanceStatusAddDTO;
    }


    /**
     * 生成update测试数据
     * @return AttendanceStatusUpdateDTO
     */
    public AttendanceStatusUpdateDTO getAttendanceStatusUpdateDTO(AttendanceStatusVO attendanceStatusVO){
        return attendanceStatusService.selectDOById(attendanceStatusVO.getId(), SITE_ID).to(AttendanceStatusUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return AttendanceStatusQuery
     */
    public AttendanceStatusQuery getAttendanceStatusQuery() {
        AttendanceStatusQuery attendanceStatusQuery = new AttendanceStatusQuery();
        List<AttendanceStatusDO> attendanceStatusDOList = attendanceStatusService.list(new AttendanceStatusDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(attendanceStatusDOList)) {
            AttendanceStatusDO attendanceStatusDO = attendanceStatusDOList.get(0);
            attendanceStatusQuery = attendanceStatusDO.to(AttendanceStatusQuery.class);
            if (attendanceStatusDO.getDate() != null) {
                attendanceStatusQuery.setDateStart(DateKit.getBeforeDay(attendanceStatusDO.getDate(),-1));
                attendanceStatusQuery.setDateEnd(DateKit.getBeforeDay(attendanceStatusDO.getDate(),1));
            }
            if (attendanceStatusDO.getGmtCreate() != null) {
                attendanceStatusQuery.setGmtCreateStart(DateKit.getBeforeDay(attendanceStatusDO.getGmtCreate(),-1));
                attendanceStatusQuery.setGmtCreateEnd(DateKit.getBeforeDay(attendanceStatusDO.getGmtCreate(),1));
            }
            if (attendanceStatusDO.getGmtModified() != null) {
                attendanceStatusQuery.setGmtModifiedStart(DateKit.getBeforeDay(attendanceStatusDO.getGmtModified(),-1));
                attendanceStatusQuery.setGmtModifiedEnd(DateKit.getBeforeDay(attendanceStatusDO.getGmtModified(),1));
            }
        }
        return attendanceStatusQuery;
    }

    /**
     * 保存示例
     * @return AttendanceStatusVO
     */
    public AttendanceStatusVO saveAttendanceStatusExample(){
        AttendanceStatusAddDTO addDTO = this.getAttendanceStatusAddDTO();
        AttendanceStatusVO attendanceStatusVO = attendanceStatusService.save(addDTO,buildTokenUser());
        return attendanceStatusVO;
    }


}

